package com.huo.filestransport.service;

import com.huo.filestransport.dao.FtpFileInfoDao;
import com.huo.filestransport.dao.FtpfilelogDao;
import com.huo.filestransport.entity.FtpFileInfoEntity;
import com.huo.filestransport.entity.Ftpfilelog;
import com.huo.util.CountUtil;
import com.huo.util.DateUtils;
import com.huo.util.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TransportMonitorService {

	@Autowired
	private FtpFileInfoDao ftpFileInfoDao;
	
	@Autowired
	private FtpfilelogDao FtpfilelogDao;
	
	public List<FtpFileInfoEntity> ftpFileInfoList(Query query){
		List<FtpFileInfoEntity> list = ftpFileInfoDao.selectAll(query);
		for(FtpFileInfoEntity ffie : list) {
			ffie.setUpdatetimeStr(DateUtils.formatDatetime(ffie.getUpdatetime()));
			if(ffie.getFtpfiledatetime()!= null && !"".equals(ffie.getFtpfiledatetime())){
				ffie.setFtpfiledatetimeStr(DateUtils.longToDate(Long.valueOf(ffie.getFtpfiledatetime())));
			}
			if(ffie.getFtpfilesize() != null){
				ffie.setFtpfilesizeStr(CountUtil.countFileSize(ffie.getFtpfilesize()));
			}
		}
		
		return list;
	}
	
	public int selectCount(Query query){
		return ftpFileInfoDao.selectCount(query);
	}
	
	public List<Ftpfilelog> ftpfilelogList(Query query){
		List<Ftpfilelog> list = FtpfilelogDao.selectAll(query);
		for(Ftpfilelog log : list) {
			if(log.getFtpfiledatetime() != null){
				log.setFtpfiledatetimeStr(DateUtils.longToDate(Long.valueOf(log.getFtpfiledatetime())));
			}
			if(log.getBegintime() != null){
				log.setBegintimeStr(DateUtils.formatDatetime(log.getBegintime()));
			}
			if(log.getEndtime() != null){
				log.setEndtimeStr(DateUtils.formatDatetime(log.getEndtime()));
			}
			if(log.getFtpfilesize() != null){
				log.setFtpfilesizeStr(CountUtil.countFileSize(log.getFtpfilesize()));
			}
		}
		return list;
	}
	
	public int selectLogCount(Query query){
		return FtpfilelogDao.selectCount(query);
	}
}
